/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.ppm.dat.view;

import bgu.ppm.dat.model.Table;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author User
 */
public class DatasetUtils {

    public static CategoryDataset createDataset(Table table) {
//        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
//        for (int j = 0; j < table.getRowHeaders().length; j++) {
//            for (int i = 0; i < table.getColumnHeaders().length; i++) {
//                String series = join(table.getColumnHeaders()[i], "\n");
//                String categories = join(table.getRowHeaders()[j], " - ");
//
//                if (table.getCell(i, j) != null) {
//                    dataset.addValue((Number) table.getCell(i, j), series, categories);
//                } else {
//                    dataset.addValue(0D, series, categories);
//                }
//            }
//        }

        
        FastCategoryDataset result = new FastCategoryDataset(table);
        
        //dataset.

        return result;
    }

    public static String join(Object[] data, String delim) {
        StringBuilder str = new StringBuilder();

        for (Object o : data) {
            str.append(o).append(delim);
        }

        if (str.length() >= delim.length()) {
            str.delete(str.length() - delim.length(), str.length());
        }

        return str.toString();
    }
}
